#include "test7.h"
#include "ui_test7.h"
#include <QTime>
#include <QTableWidgetItem>

test7::test7(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::test7)
{
    ui->setupUi(this);
    initital();
}

test7::~test7()
{
    delete ui;
}

void test7::initital()
{
    int row = 8;
    int column = 5;
    QStringList table_label;
    table_label<<"数字1"<<"数字2"<<"数字3"<<"数字4"<<"数字5";
    ui->tableWidget->setRowCount(row);
    ui->tableWidget->setColumnCount(column);
    ui->tableWidget->setHorizontalHeaderLabels(table_label);
    for(int i=0;i<column;i++)
    {
        for(int j=0;j<row;j++)
        {
            ui->tableWidget->setItem(j,i,new QTableWidgetItem(QString::number(qrand()%50)));
        }
    }
}


void test7::on_pushButton_clicked()
{
    int column = ui->tableWidget->columnCount();
    int row = ui->tableWidget->rowCount();
    int halfrow = row/2;
    row--;
    for(int i=0;i<halfrow;i++)
    {
        QStringList data;
        for(int j=0;j<column;j++)
        {
            data.append(ui->tableWidget->item(i,j)->text());
        }
        for(int j=0;j<column;j++)
        {
            ui->tableWidget->setItem(i,j,new QTableWidgetItem(ui->tableWidget->item(row-i,j)->text()));
            ui->tableWidget->setItem(row-i,j,new QTableWidgetItem(data.at(j)));

        }
    }
}
